
#import <QuartzCore/QuartzCore.h>
#import "FindLampResultWebViewController.h"
#import "NSString+VoiceOver.h"

@interface FindLampResultWebViewController ()

@property (strong, nonatomic) IBOutlet UILabel *topViewSubTitle;
@property (strong, nonatomic) IBOutlet UILabel *topViewTitle;
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (strong, nonatomic) IBOutlet UIView *tableHeaderView;
@property (strong, nonatomic) IBOutlet UILabel *tableHeaderViewLabel;

@property (strong, nonatomic) NSString *documentName;

@end

@implementation FindLampResultWebViewController

- (instancetype)initWithDefaultNibAndDocumentName:(NSString *)documentName
{
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        self.documentName = documentName;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    self.webView.dataDetectorTypes = UIDataDetectorTypeNone;
    self.navigationItem.title = self.title;
    
    NSString *locale = @"sv";
    NSString *file = [locale stringByAppendingFormat:@"_%@", self.documentName];
    NSLog(@"%@", file);
    NSString *html = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] 
                                                         pathForResource:file
                                                         ofType:@"html"] 
                                               encoding:NSUTF8StringEncoding error:nil];
    html = [html stringByReplacingOccurrencesOfString:@"../" withString:@""];
    if (voiceoverEnabled) {
        html = [html stringByOptimizingForVoiceOver];
    }
    [self.webView loadHTMLString:html baseURL:[[NSBundle mainBundle] bundleURL]]; 
    
    self.topViewSubTitle.text = self.subTitle;
    self.topViewSubTitle.accessibilityLabel = [self.subTitle stringByOptimizingForVoiceOver];
    
    self.tableHeaderViewLabel.text = self.headerViewLabel;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
